<?php
namespace app\index\controller;

use app\core\Outcontroller;
use Qiniu\Http\Request;
use think\Db;

class Tshow extends Outcontroller
{
    public function _empty($name){
        return $name;
    }

    public function index(){ //搭配列表页面
        $this->assign('website',[
            'title' => '-时尚秀'
        ]);
        $control = $this->request->controller();
        $action  = $this->request->action();

        $type = model('type');
        $type = $type->field('id,name,en_name,p_en_name')->select();
        //dump($type->toArray());
        $first_type = [];
        foreach ($type as $val){
            $val = [
                'id'        => $val->id,
                'name'      => $val->name,
                'en_name'   => $val->en_name,
                'p_en_name' => $val->p_en_name,
            ];
            if(!$val['p_en_name']){
                $val['sub_menu'] = [];
                $first_type[$val['en_name']] = $val;
            }else{
                $first_type[$val['p_en_name']]['sub_menu'][] = $val;
            }
        }

        $shop = model('shop');
        $shop_res = $shop->field('id,thumb,title');
        if(isset($do_type) && $do_type){
            $shop_res = $shop_res->whereLike('type_id','%,'.$do_type.',%');
        }
        if(isset($do_flag) && $do_flag){
            $shop_res = $shop_res->whereLike('flag_id','%,'.$do_flag.',%');
        }
        $shop_res = $shop_res->where(['row_status'=>0])->order('id desc')->limit(0,50)->select();

        $this->assign('t',$this->request->param('t'));
        $this->assign('q',$this->request->param('q'));
        $this->assign('sort',$this->request->param('sort'));
        $this->assign('type',$first_type);
        $this->assign('nav_active',url($control.'/'.$action));
        $this->assign('shop',$shop_res);
        $this->show('tshow/index');
    }
}
